//
//  RSConfig.m
//  ChangeLanguageDemo
//
//  Created by thinkjoy on 2017/8/15.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSConfig.h"


static NSString *const RSAppleLanguagesKey = @"AppleLanguages";
static NSString *const RSAppUseLanguageKey = @"AppUseLanguageKey";

@implementation RSConfig

+ (void)setAppUseLanguage:(NSString *)appUseLanguage
{
    [self resetAppSystemLanguage:appUseLanguage];
}

+ (NSString *)appUseLanguage
{
    return [[NSUserDefaults standardUserDefaults] valueForKey:RSAppUseLanguageKey];
}

/**
 重置系统语言
 */
+ (void)resetAppSystemLanguage
{
    [self resetAppSystemLanguage:nil];
}

+ (void)resetAppSystemLanguage:(NSString *)appUseLanguage
{
    //如果appUseLanguage为nil,跟随系统
    if (appUseLanguage==nil || appUseLanguage.length<1) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:RSAppUseLanguageKey];
        [[NSUserDefaults standardUserDefaults] setValue:nil forKey:RSAppleLanguagesKey];
    }else{
        //用户自定义
        [[NSUserDefaults standardUserDefaults] setValue:appUseLanguage forKey:RSAppUseLanguageKey];
        [[NSUserDefaults standardUserDefaults] setValue:@[appUseLanguage] forKey:RSAppleLanguagesKey];
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
